package view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JMenu;
import javax.swing.JMenuItem;

import com.hexidec.util.Translatrix;

import eventHandling.EventBus;
import eventHandling.EventTyp.Type;

/**
 * This dialog is called when sb wants to import a lesson.
 * @author sloth42
 *
 */
public class ImportDialog {

	private final int MENU_ITEM_INDEX = 3;
	private JMenuItem menuItemImport = new JMenuItem(Translatrix
			.getTranslationString("import"));
	private EventBus eventBus;

	public ImportDialog(EventBus eventBus) {
		this.eventBus = eventBus;
	}

	private void initMenuItem() {
		menuItemImport.addActionListener(new ActionListener() {

			public void actionPerformed(ActionEvent arg0) {
				eventBus.fireEvent(Type.OPEN_IMPORT_DIALOG);
			}
		});
	}

	/**
	 * Inserts the import-JMenuItem into the JMenu.
	 * @param menu the destination JMenu
	 */
	public void insertMenuItem(JMenu menu) {
		initMenuItem();
		menu.add(menuItemImport, MENU_ITEM_INDEX);
	}

}
